cmake_minimum_required(VERSION 3.5)

project(kaiFaZhuShou VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Svg)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Svg)

# 包含项目头文件目录
include_directories(${CMAKE_SOURCE_DIR}/include)
set(HEADER_DIR ${CMAKE_SOURCE_DIR}/include)

# 添加源代码目录到变量中以便之后使用
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)

# 添加资源文件
qt5_add_resources(RESOURCES_RCC ${CMAKE_SOURCE_DIR}/resources/resources.qrc)

set(PROJECT_SOURCES
         ${RESOURCES_RCC}
         ${SOURCE_DIR}/main.cpp
         ${SOURCE_DIR}/mainwindow.cpp
         ${HEADER_DIR}/mainwindow.h
         ${SOURCE_DIR}/component/window.cpp
         ${HEADER_DIR}/component/window.h
         ${HEADER_DIR}/utils/WindowControl.h
         ${SOURCE_DIR}/utils/WindowControl.cpp
         ${HEADER_DIR}/title/TitleBar.h
         ${SOURCE_DIR}/title/TitleBar.cpp
         ${HEADER_DIR}/statusbar/StatusBar.h
         ${SOURCE_DIR}/statusbar/StatusBar.cpp
         

)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(kaiFaZhuShou
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET kaiFaZhuShou APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(kaiFaZhuShou SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(kaiFaZhuShou
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(kaiFaZhuShou PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Svg)

set_target_properties(kaiFaZhuShou PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE OFF
    WIN32_EXECUTABLE OFF
)

install(TARGETS kaiFaZhuShou
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(kaiFaZhuShou)
endif()
